﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 易容酒店管理系统
{
    public partial class Stock : Form
    {
        public Stock()
        {
            InitializeComponent();
        }

        private void picReturn_Click(object sender, EventArgs e)
        {
            Main_function newzMain_function = new Main_function();
            newzMain_function.Show();
            newzMain_function.TopLevel = false;
            Method.frm.panel1.Controls.Clear();
            Method.frm.panel1.Controls.Add(newzMain_function);
        }

        private void Stock_Load(object sender, EventArgs e)
        {
            ADD();
            ADDin();
        }
        public void ADD()
        {
            listView1.Items.Clear();
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            SqlConnection con = new SqlConnection(Link);
            string Sql = "select * from Goods";
            SqlDataAdapter add = new SqlDataAdapter(Sql, con);
            DataSet set = new DataSet();
            add.Fill(set, "Goods");
            DataTable table = set.Tables["Goods"];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow drow = table.Rows[i];
                ListViewItem lvi = new ListViewItem(drow[0].ToString());
                lvi.SubItems.Add(drow[0].ToString());
                lvi.SubItems.Add(drow[1].ToString());
                lvi.SubItems.Add(drow[2].ToString());
                listView1.Items.Add(lvi);
            }
        }
        public void ADDin()
        {
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            SqlConnection con = new SqlConnection(Link);
            string Sql = "select * from Goods;";
            SqlDataAdapter Add = new SqlDataAdapter(Sql, con);
            DataSet set = new DataSet();
            Add.Fill(set, "Goods");
            DataTable table = set.Tables["Goods"];

            comboBox1.DisplayMember = "GoodsType";
            comboBox1.DataSource = set.Tables["Goods"];
        }
        //添加
        private void button1_Click(object sender, EventArgs e)
        {
            int num = 0;
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            num += Convert.ToInt32(numericUpDown1.Value);
            using (SqlConnection con = new SqlConnection(Link))
            {
                string Sql = "select Number from Goods where GoodsType='" + comboBox1.Text + "';";
                using (SqlCommand cmd = new SqlCommand(Sql, con))
                {
                    con.Open();
                    num += Convert.ToInt32(cmd.ExecuteScalar());
                    con.Close();
                }
                string Sql2 = "update Goods set Number='" + num.ToString() + "' where  GoodsType='" + comboBox1.Text + "';";
                using (SqlCommand cmd = new SqlCommand(Sql2, con))
                {
                    con.Open();
                    int i = cmd.ExecuteNonQuery();
                    if (i > 0)
                    {
                        MessageBox.Show("添加完成");
                    }
                }
            }
            ADD();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Main_function newzMain_function = new Main_function();

            newzMain_function.TopLevel = false;
            Method.frm.panel1.Controls.Clear();
            Method.frm.panel1.Controls.Add(newzMain_function);
            newzMain_function.Show();
            Method.SetDouble(Method.frm);
        }
    }
}
